package com.twinkle.dbmanage.dao.impl;

import com.twinkle.dbmanage.dao.ICommonDao;
import com.twinkle.dbmanage.util.JDBCTemplate;
import com.twinkle.dbmanage.vo.DBConfig;
import com.twinkle.dbmanage.vo.DBField;

import java.util.List;

/**
 * @author Twinkle
 */
public class ICommonDaoImpl implements ICommonDao {
    private JDBCTemplate jdbcTemplate;

    public ICommonDaoImpl(DBConfig config) {
        this.jdbcTemplate = new JDBCTemplate(config);
    }

    @Override
    public List<String> getTableName(String dbName) {
        return jdbcTemplate.getTables(dbName);
    }

    @Override
    public List<DBField> getFieldInfo(String dbName, String tableName) {
        return jdbcTemplate.getFields(dbName, tableName);
    }

    @Override
    public List<Object[]> getExecuteResult(String sql) {
        return jdbcTemplate.executeQuery(sql);
    }

    @Override
    public int getExecuteRowsCount(String sql) {
        return jdbcTemplate.executeUpdate(sql);
    }

    @Override
    public String[] getTableHeader() {
        return jdbcTemplate.getHeader();
    }

}
